package org.n.shop.controller;

import lombok.AllArgsConstructor;
import org.n.shop.annotation.RequiresLogin;
import org.n.shop.domain.entity.Comment;
import org.n.shop.result.RestResult;
import org.n.shop.service.CommentService;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/comment")
@AllArgsConstructor
public class CommentController {
    private CommentService commentService;

    @RequestMapping("/all")
    public RestResult all(@RequestParam int page, @RequestParam int pageSize, @RequestParam int commodityId) {
        return commentService.all(page, pageSize, commodityId);
    }

    @RequiresLogin
    @RequestMapping("/add")
    public RestResult add(@RequestHeader("authorization") String authorization,
                          @RequestBody Comment comment) {
        return commentService.add(authorization, comment);
    }

    @RequiresLogin
    @RequestMapping("/commented")
    public RestResult isCommented(@RequestParam("commodityId") int commodityId,
                                  @RequestHeader("authorization") String authorization) {
        return commentService.isCommented(commodityId, authorization);
    }
}
